//---------------------------------------------------------------------------- Package
const _ = require('lodash')
//---------------------------------------------------------------------------- dateFormat
/**
 * 日期格式 转换 时间戳
 */
exports.format = function (return_time) {
  let year
  let month
  let day
  let hour
  let minute
  let second

  // 分割字符串
  let prioc = []
  prioc = return_time.split('T')
  let prior_date = prioc[0].split('-')
  let prior_time
  if (prioc[1] != undefined && prioc[1] != '') {
    prior_time = prioc[1].split(':')
  } else {
    prior_time = [ '00', '00', '00' ]
  }

  // 处理 日期
  year    = prior_date[0] * 1
  month   = prior_date[1] * 1 - 1
  day     = prior_date[2] * 1
  hour    = prior_time[0] * 1
  minute  = prior_time[1] * 1
  second  = prior_time[2] * 1

  let time = new Date( year, month, day, hour, minute, second )
  time = time.getTime() / 1000
  return time
}
//---------------------------------------------------------------------------- convert_Data
exports.con_data = function (time) {
  var d = new Date(time * 1000)
  let date = d.toLocaleString()
  let prioc = date.split(', ')
  
  //判断是否需要补0
  date = prioc[0].split('/')
  let Y = date[2]
  let M = date[0]
  let D = date[1]
  if ( M/10 < 1 ) {
    M = '0'+M
  }
  if ( D/10 < 1 ) {
    D = '0'+D
  }
  
  // 重新组合 返回结果
  date = Y + '-' + M + '-' + D
  return date
}
//---------------------------------------------------------------------------- convert_Time
exports.con_time = function (time) {
  var d = new Date(time * 1000)
  let date = d.toLocaleString()
  let prioc = date.split(' ')

  return prioc[1]
}
//---------------------------------------------------------------------------- convert_DataTime